package com.fishing.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;

import QL.ButlerMailGiftLogQueryRequest;
import QL.ButlerMailGiftLogQueryResponse;
import QL.QLClient;

@Controller
public class GameGift {
	
	private static QLClient client = new QLClient();
	
	//region 跳转礼物查询页面
    @RequestMapping("game/gift")
	public ModelAndView gift(HttpServletRequest request)throws Exception{
		ModelAndView mav = new ModelAndView("game/giftquery");
		return mav;
	}
    //endregion
    
    //region 礼物记录查询
    @ResponseBody
    @RequestMapping(value="gift/query",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    public Map<String,Object> query(HttpServletRequest request, String PageIndex, String PageCount, String UserId, String StartTime, String EndTime) {
    	//定义变量
    	Map<String,Object> map = new HashMap<String, Object>();
    	
    	ButlerMailGiftLogQueryRequest req = new ButlerMailGiftLogQueryRequest();
    	req.ZoneId = (int)request.getSession().getAttribute("ZoneId");
    	req.PageIndex = Integer.parseInt(PageIndex) - 1;
    	req.PageCount = Integer.parseInt(PageCount);
    	req.FilterUserId = UserId == ""? 0 : Integer.parseInt(UserId);
    	req.IsFilterDateTime = (StartTime.isEmpty() && EndTime.isEmpty()) == true ? false : true;
    	req.FilterBeginTime = req.IsFilterDateTime == true ? StartTime : "null";
    	req.FilterEndTime = req.IsFilterDateTime == true ? EndTime : "null";
    	ButlerMailGiftLogQueryResponse rsp = new ButlerMailGiftLogQueryResponse();
    	if (req.ZoneId < 0)
			client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
		client.Execute(req, rsp);
    	
		//获取返回值
		map.put("status", "200");
		map.put("message", "");
		map.put("data", rsp.LogItems);
		map.put("count", rsp.TotalCount);
    	return map;
    }
    //endregion
}
